<?php
namespace app\admin\model;

use think\Model;

class ProCfgModel extends Model{
	protected $name = 'product_cfg';

	/**
	 * [获取信息]
	 */
	public function getCfgInfoByWhere($where='',$is_page=false,$offset=0,$limit=20,$order=''){
		if($is_page){
			return $this->where($where)->where($this->whereCansee())->limit($offset, $limit)->order($order)->select();
		}else{
			return $this->where($where)->where($this->whereCansee())->order($order)->select();
		}
	}

	/**
	 * [删除产品配置]
     */
    public function delProConfig($param){
    	if($this->where('id',$param)->delete()){
    		return ['code'=>1,'msg'=>'删除成功'];
    	}else{
    		return ['code'=>0,'msg'=>'删除失败'];
    	}
    }

    /**
	 * [添加产品配置]
     */
    public function addProConfig($param){
    	if($this->insert($param)){
    		return ['code'=>1,'msg'=>'添加成功'];
    	}else{
    		return ['code'=>0,'msg'=>'添加失败'];
    	}
    }

    /**
	 * [编辑产品配置]
     */
    public function editProConfig($param){
    	try{
    		$this->where('id',$param['id'])->update($param);
    		return ['code'=>1,'msg'=>'编辑成功'];
    	}catch(Exception $e){
    		return ['code'=>0,'msg'=>'编辑失败'.$e->getMessage()];
    	}
    }
}